<%--
  Created by IntelliJ IDEA.
  User:lixiangling
  Date: 2018-08-14
  Time: 16:52:42
  desc: 用户扩展信息的展示界面
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
	<%@ include file="../../include/head.jsp"%>
	<%@ include file="../../include/layui.jsp"%>
	<title>用户扩展信息列表</title>
</head>
<body layadmin-themealias="default">
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-form layui-card-header layuiadmin-card-header-auto">
			<!-- start 搜索框 -->
			<div class="layui-collapse">
				<div class="layui-colla-item">
					<h2 class="layui-colla-title">搜索操作</h2>
					<div class="layui-colla-content layui-show">
						<!-- 搜索相关表单及控件 参照`表单`样式 -->
						<form class="layui-form layui-form-pane" id="search-form">
							
							<!-- start 行信息 -->
							<div class="layui-form-item" style="margin-bottom: 0;">
								<!-- start 单个元素项 -->
								<div class="layui-inline">
									<label class="layui-form-label"></label>
									<div class="layui-input-inline">
									<input type="text"  id="nickName" name="nickName" lay-verify="title" autocomplete="off" placeholder="请输入"  class="layui-input">
									</div>
								</div>
								<!-- end 单个元素项 -->
								<!-- start 单个元素项 -->
								<div class="layui-inline">
									<label class="layui-form-label"></label>
									<div class="layui-input-inline">
									<input type="text"  id="systemLotteryCount" name="systemLotteryCount" lay-verify="title" autocomplete="off" placeholder="请输入"  class="layui-input">
									</div>
								</div>
								<!-- end 单个元素项 -->
								<!-- start 单个元素项 -->
								<div class="layui-inline">
									<button type="button" class="layui-btn layui-btn-radius btn-min-width" id="search-btn">
									<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
									</button>
									<button type="reset" class="layui-btn layui-btn-radius layui-btn-primary btn-min-width">清空</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
			<!-- end 搜索框 -->
		</div>
		<div class="layui-card-body" >
			<!-- start 表格内容 -->
			<div>
				<!-- start 顶部按钮 -->
				<div class="layui-btn-group btn-group-bottom" btn-listener>
					<shiro:hasPermission name="user:userData_add">
						<button class="layui-btn layui-btn-orange layui-btn-sm" lay-event="add">
							<i class="layui-icon">&#xe654;</i>添加
						</button>
					</shiro:hasPermission>
					<shiro:hasPermission name="user:userData_del">
						<button class="layui-btn layui-btn-red layui-btn-sm" lay-event="delBatch" not-null="1">
							<i class="layui-icon">&#xe640;</i>删除
						</button>
					</shiro:hasPermission>
					<shiro:hasPermission name="user:userData_export">
						<button class="layui-btn layui-btn-green layui-btn-sm" lay-event="exportData">
							<i class="layui-icon">&#xe621;</i>导出
						</button>
					</shiro:hasPermission>
				</div>
				<!-- end 顶部按钮 -->
				<!-- start 表头按钮 -->
				<div class="table-header-btn-group" btn-listener>
					<shiro:hasPermission name="user:userData_turnOn">
						<a lay-event="turnOn" not-null="1"><i class="layui-icon"><span>&#xe652;</span>启用</i></a>
					</shiro:hasPermission>
					<shiro:hasPermission name="user:userData_turnOff">
						<a lay-event="turnOff" not-null="1"><i class="layui-icon"><span>&#xe651;</span>禁用</i></a>
					</shiro:hasPermission>
				</div>
				<!-- end 表头按钮 -->
				<table class="layui-hide" id="data-table" lay-filter="data-table"></table>
			</div>

			<!-- 行内操作按钮 -->
			<script type="text/html" id="toolBar">
				<a class="layui-btn-xs" title="查看" style="cursor:pointer" lay-event="detail"><i class="layui-icon" style="font-size: 40px; color: #1E9FFF;font-weight: bold">&#xe60a;</i></a>
				<shiro:hasPermission name="user:userData_modify">
					<a class="layui-btn-xs" title="编辑" style="cursor:pointer" lay-event="edit"><i class="layui-icon" style="font-size: 40px; color: #1E9FFF;font-weight: bold">&#xe642;</i></a>
				</shiro:hasPermission>
			</script>
			<!-- end 表格内容 -->
		</div>
	</div>
</div>
<script type="text/javascript">

    layui.use(['index', 'element', 'layer', 'table','laydate'], function(){
        var table = layui.table;
        
        //方法级渲染
        table.render({
            elem: '#data-table',
            url:  '${ctx}/user/userData/list',
            cols: [[
                
				{field:'userId', title: '用户ID', checkbox: true}
				,{field:'nationalityId', title: '国家ID',width:120}
				,{field:'provinceId', title: '省份ID',width:120}
				,{field:'cityId', title: '城市ID',width:120}
				,{field:'enableStatus', title: '启用状态',width:120,templet:enableStatusTpl}
				,{field:'creater', title: '创建人',width:120}
				,{field:'createTime', title: '创建时间',width:120}
				,{field:'modifier', title: '修改人',width:120}
				,{field:'modifyTime', title: '修改时间',width:120}
				,{field:'reorder', title: '排序',width:120}
				,{field:'remark', title: '描述',width:120}
				,{field:'channelId', title: '',width:120}
				,{field:'channelIdOld', title: '',width:120}
				,{field:'baiduUserId', title: '',width:120}
				,{field:'baiduUserIdOld', title: '',width:120}
				,{field:'userEmail', title: '会员邮箱',width:120}
				,{field:'macId', title: '',width:120}
				,{field:'imei', title: '记录手机的IMEI码',width:120}
				,{field:'deviceToken', title: '',width:120}
				,{field:'imageUrl', title: '',width:120}
				,{field:'nickName', title: '',width:120}
				,{field:'lotteryCount', title: '可抽奖次数',width:120}
				,{field:'bankUsername', title: '开户人姓名',width:120}
				,{field:'bankCard', title: '银行卡号',width:120}
				,{field:'bankName', title: '银行名称',width:120}
				,{field:'contactPhone', title: '联系电话',width:120}
				,{field:'securePwd', title: '安全口令',width:120}
				,{field:'invitAwardLottery', title: '给邀请人奖励抽奖次数',width:120}
				,{field:'systemLotteryCount', title: '',width:120}
				,{field:'isClickHome', title: '',width:120}
				,{field:'sex', title: '1男2女',width:120}
				,{field:'birthday', title: '生日',width:120}
				,{field:'userLocation', title: '所在地',width:120}
				,{field:'userOccupation', title: '职业',width:120}
				,{field:'qualifications', title: '学历',width:120}
				,{field:'countyId', title: '区县id',width:120}
				,{field:'secureFaultCount', title: 'svip退款安全口令错误次数',width:120}
				,{field:'padUnique', title: '用户手机唯一标识',width:120}
				,{field:'inviteCode', title: '邀请码，用于国庆邀请活动',width:120}
				,{field:'loginDays', title: '累积登陆天数',width:120}
				,{field:'cuid', title: 'cuid',width:120}
				,{field:'secureFaultCount2', title: '',width:120}
				,{field:'secureFaultCount3', title: 'svip退款安全口令错误次数',width:120}
                ,{title: '操作', width: 90, toolbar: '#toolBar',fixed:'right'}
            ]]
            ,page: true
        });
        // 搜索按钮点事件
        $('#search-btn').on('click', function(){
            table.reload('data-table', {
                where: getParamJson('#search-form'),
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        // 校验初始化
        var form = layui.form;
        form.verify({
            
			nickName: function(value, item){
				if(!/^.{0,500}$/.test(value)){
					return '不能超过500位'
				}
			}
			,systemLotteryCount: function(value, item){
				if(value > 2147483647){
					return '必须是2147483647以内的正整数'
				}
			}
        });

        // 行操作事件定义
        var tableEvent = {
            detail: function(obj){
                var data = obj.data; //获得当前行数据
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                openTabsPage('${ctx}/user/userData/detail?id=' + data.userId, '查看用户扩展信息 - ' + data.userId);
            },
            del: function(obj){
                var data = obj.data; //获得当前行数据
                parent.layer.confirm('真的删除行么', function(index){
                    parent.layer.close(index);
                    //向服务端发送删除指令
                    $.post('${ctx}/user/userData/del', {id: data.userId},function(result){
                        if(result.code == 0){
                            parent.layer.alert('操作成功', {
                                yes: function(index){
                                    parent.layer.close(index);
                                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                }
                            });
                        }else{
                            parent.layer.msg(result.msg || '操作失败');
                        }
                    }, 'json');
                });
            },
            edit: function(obj){
                var data = obj.data; //获得当前行数据
                openTabsPage('${ctx}/user/userData/edit?id=' + data.userId, '编辑用户扩展信息 - ' + data.userId);
            }
        };

        // 其他操作按钮事件定义
        var otherBtnEvent = {
            getPrimaryKeyParams: function(data){
                var params = '';
                $.each(data, function(i, item){
                    if(i !== 0) params += '&';
                    params += 'id=' + item.userId;
                });
                return params
            },
            add: function(){
                openTabsPage('${ctx}/user/userData/newInfo?id=', '添加用户扩展信息');
            },
            delBatch: function(data, length, isAll){
                var params = otherBtnEvent.getPrimaryKeyParams(data);
                parent.layer.confirm('真的删除选中的行么', function(index){
                    parent.layer.close(index);
                    //向服务端发送删除指令
                    $.post('${ctx}/user/userData/del', params,function(result){
                        if(result.code == 0){
                            parent.layer.alert('操作成功', {
                                yes: function(index){
                                    parent.layer.close(index);
                                    // 更新表格
                                    table.reload('data-table');
                                }
                            });
                        }else{
                            parent.layer.msg(result.msg || '操作失败');
                        }
                    }, 'json');
                });
            },
            exportData: function(data, length, isAll){ //导出
                // 数量限制
                var params = $.param({
                    page: 1,
                    limit: 1000
                }, true);
                // 选中的数据
                var primaryKeys = otherBtnEvent.getPrimaryKeyParams(data);
                // 搜索参数

                // 聚合
                params = params + '&' + primaryKeys;
                window.open('${ctx}/user/userData/export?' + params);
            },
            turnOn: function(data, length, isAll){ // 启用
                var params = otherBtnEvent.getPrimaryKeyParams(data);
                $.post('${ctx}/user/userData/turnOn', params,function(result){
                    if(result.code == 0){
                        parent.layer.msg('操作成功');
                        // 更新表格
                        table.reload('data-table');
                    }else{
                        parent.layer.msg(result.msg || '操作失败');
                    }
                }, 'json');
            },
            turnOff: function(data, length, isAll){ // 停用
                var params = otherBtnEvent.getPrimaryKeyParams(data);
                $.post('${ctx}/user/userData/turnOff', params,function(result){
                    if(result.code == 0){
                        parent.layer.msg('操作成功');
                        // 更新表格
                        table.reload('data-table');
                    }else{
                        parent.layer.msg(result.msg || '操作失败');
                    }
                }, 'json');
            }
        };

        // 初始化监听事件
        initTableEvnet(table, 'data-table', tableEvent, otherBtnEvent);
    });

</script>
</body>
</html>
